package com.bsj.power.common.mapper;

import com.bsj.power.common.def.entity.gb28181.Device;
import com.bsj.power.common.def.entity.gb28181.DeviceChannel;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description
 * @Author zhaoyang
 * @Date 2024/4/27 19:46
 */
@Mapper
@Repository
public interface PlatformChannelMapper {

    @Delete("<script> " +
            "DELETE from tab_platform_gb_channel WHERE device_channel_id in " +
            "( select  temp.device_channel_id from " +
            "(select pgc.device_channel_id from wvp_platform_gb_channel pgc " +
            "left join tab_device_channel dc on dc.id = pgc.device_channel_id where dc.device_id  =#{deviceId} " +
            ") temp)" +
            "</script>")
    int delChannelForDeviceId(String deviceId);


    List<Device> queryDeviceInfoByPlatformIdAndChannelId(String platformId, String channelId);


    List<String> queryParentPlatformByChannelId(String channelId);

//    List<DeviceChannel> queryChannelInParentPlatform(@Param("platformId") String platformId, @Param("channelId") String channelId);

    @Select("select d.*\n" +
            "from tab_platform_gb_channel pgc\n" +
            "         left join tab_device_channel dc on dc.id = pgc.device_channel_id\n" +
            "         left join tab_device d on dc.device_id = d.device_id\n" +
            "where dc.channel_id = #{channelId} and pgc.platform_id=#{platformId}")
    List<Device> queryVideoDeviceByPlatformIdAndChannelId(@Param("platformId") String platformId, @Param("channelId") String channelId);


}
